<?php
include_once('common/header.php');
$intLimit		= PHOTO_LIMIT;
$strRefer		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$intUserId		= $objUser->id;
$intAlbumId		= $objRequest->getParam('albumid',0);
$intPage 		= $objRequest->getParam('page', 1);
$intTotal			= 0;
$intOffset			= ($intPage - 1) * $intLimit;
$objPhoto			= new Photo();
$objBehaviour		= new Behaviour();
$objVfriendUser		= new Vfriend_User();
$arrAlbumInfo		= $objPhoto->getAlbumInfo($intAlbumId);
$intTypeRelation	= $objVfriendUser->getRelationType($objUser->id, $AppUI->id);
$intType			= 0;
$intPerm			= isset($arrAlbumInfo['perm']) ? $arrAlbumInfo['perm'] : -1;
if($AppUI->id) {
	$objBehaviour->updateRead($AppUI->id,$intAlbumId,2,21);
}
if($intPerm > -1) {	
	if($intPerm == 1) {
		if($intTypeRelation < 2) {
			$strMessage	= $arrMessage[7];
			$strMessage	= str_replace('[strFullname]',$objUser->fullnamevn, $strMessage);
			$strRefer	= $strRefer ? $strRefer : Vfriend_Function::linkFullhouseForPhoto($objUser->hex,$objUser->username);
			Vfriend_Function::setMsg($strMessage);
			Vfriend_Function::redirect($strRefer);
		} else {
			$intType = 1;
		}
	}
	elseif($intPerm == 2)  {
		if($arrAlbumInfo['userid'] != $AppUI->id ) {
			$strMessage	= $arrMessage[7];
			$strMessage	= str_replace('[strFullname]',$objUser->fullnamevn, $strMessage);
			$strRefer	= $strRefer ? $strRefer : Vfriend_Function::linkFullhouseForPhoto($objUser->hex,$objUser->username);
			Vfriend_Function::setMsg($strMessage);
			Vfriend_Function::redirect($strRefer);
		} else {
			$intType = 2;
		}
	}
	$arrResult		= $objPhoto->getPhotoByAlbum($intAlbumId, $intType, $intOffset, $intLimit, $intTotal);
	$this->view->arrResult	= $arrResult;
	$this->view->album		= $arrAlbumInfo;
	$this->view->intTotal	= $intTotal;
	$this->view->intOffset	= $intOffset;
	$this->view->intLimit	= $intLimit;
	$this->view->intPage	= $intPage;
} else {
	$strRefer	= $strRefer ? $strRefer : Vfriend_Function::linkFullhouseForPhoto($objUser->hex,$objUser->username);
	Vfriend_Function::setMsg($arrMessage[8]);
	Vfriend_Function::redirect($strRefer);
}
?>